<template>
  <div style="margin-top:-18px;">
    <a-card :bordered="false">
      <div class="table-page-search-wrapper" style="background:white;" >
        <a-form layout="inline" class="formModel" style="margin-left:20px;margin-top:20px">
          <a-row :gutter="48">
           
            <a-col :md="4" :sm="24">
              <a-form-item label="区县">
                <a-input v-model="queryParam.country" placeholder="" />
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="24">
                <a-form-item label="时间">
                <a-range-picker :ranges="{ Today: [moment(), moment()], 'This Month': [moment(), moment().endOf('month')] }" v-model="selectTime" @change="onChange" class="rangePicker" /> 
               </a-form-item>
            </a-col>            
            <a-col :md="4" :sm="24">           
                <a-button  type="primary" @click="selectEvent">查询</a-button>                           
            </a-col>
          </a-row>
        </a-form>
      </div>

    

      <a-table style="margin: 0 20px 20px 20px"   :columns="columnstable" :data-source="data" 
       bordered size="middle" 
       :loading="tableLoading"
       :pagination="false"
       @change="pageShow"/>

    </a-card>
  </div>
</template>

<script>
import moment from 'moment'
import { getNowTime, getNowFormatDate } from '@/utils/util.js'
import {getInspectionTotal} from '@/api/video'
const data = []
export default {
  components: {},
  data() {
    
    return {
      columnstable,
      data,
      searchData: [],
      // create model
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      // 加载数据方法 必须为 Promise 对象
      selectedRowKeys: [],
      selectedRows: [],
      current: 1,
      pageSize: 10,
      selectTime:'',
      tableLoading:false,
      pagination: {
        total: 0,
        showTotal: (total) => `共有 ${total} 条数据`,
      },
    }
  },
  filters: {
   
  },
  created() {
    let nowtime = getNowFormatDate()
    this.selectTime = [moment(nowtime), moment(nowtime)]
    this.queryParam.startTime = nowtime+" 00:00:00"
    this.queryParam.endTime = nowtime+" 23:59:59"
    // this.queryParam.current = this.current
    // this.queryParam.pageSize = this.pageSize
  },
  computed: {
    
  },
  mounted(){
   this.getDataInfoFunction()
  },
  methods: {
    moment,
   onChange(date, dateString) {
      this.queryParam.startTime = dateString[0]+" 00:00:00"
      this.queryParam.endTime = dateString[1]+" 23:59:59"
      this.selectTime = [moment(dateString[0]), moment(dateString[1])] 
     },
    //查询
    selectEvent(){
      this.getDataInfoFunction()
      this.addShow = false
    }, 
    //获取表格数据
    getDataInfoFunction() {
      this.tableLoading = true
      getInspectionTotal(this.queryParam)
        .then((response) => {   
          // const pagination = { ...this.pagination }
          // pagination.total = response.data.total
          // pagination.pageSize = this.pageSize
          // this.pagination = pagination
          // this.pagination.current = response.data.current
          this.data = response.data
          this.tableLoading = false
        })
        .catch((error) => {
          this.tableLoading = false
        })
    },
    //分页
    pageShow(pagination) {
      this.tableLoading = true
      this.queryParam.current = pagination.current
      this.queryParam.pageSize =  pagination.pageSize
      getInspectionTotal(this.queryParam)
        .then((response) => {
          const pagination = { ...this.pagination }
          pagination.total = response.data.total
          pagination.pageSize = this.pageSize
          this.pagination = pagination
          this.pagination.current = response.data.current
          this.data = response.data.records
          this.tableLoading = false
        })
        .catch((error) => {
          this.tableLoading = false
        })
    },
    
   
  },
}
const columnstable = [
  {
    title: '区县',
    dataIndex: 'country',
    width: 100,
    align: 'center',
  },
  {
    title: '巡检目标量',
    dataIndex: 'planNum', 
    width: 100,
    align: 'center',
  },
  {
    title: '巡检完成量',
    dataIndex: 'overNum', 
    width: 100,
    align: 'center',
  },
   {
    title: '完成率',
    dataIndex: 'overRatio', 
    width: 100,
    align: 'center',
  },

]
</script>
